home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / 13h_kit / idemo.cpp < prev    next >
C/C++ Source or Header  |  1991-07-05  |  13KB  |  498 lines

  1. // IDEMO.CPP
  2.  
  3. // **************************************************************************
  4. // **************************************************************************
  5. // demonstration program for features of Mode 13h Toolkit
  6. // **************************************************************************
  7. // author: Mark Betz, 76605,2346
  8. //
  9. // developed on: July 6, 1991
  10. //
  11. // last update:  July 6, 1991
  12. // **************************************************************************
  13. // **************************************************************************
  14.  
  15.  
  16. #include <dos.h>
  17. #include <stdio.h>
  18. #include <conio.h>
  19. #include <mem.h>
  20. #include <stdlib.h>
  21. #include "images.hpp"
  22. #include "keyboard.hpp"
  23.  
  24. font small("csfont1.fnt");
  25. pcx rehack("rehack.pcx");
  26. pcx celtic("celtic.pcx");
  27. pcx title("title.pcx");
  28.  
  29. unsigned _stklen = 8192;
  30. p_rec default_pal;
  31.  
  32. void waitkey()
  33.     {
  34.     char c;
  35.     extnd s;
  36.     while (!kbhit());
  37.     getkey(&c,&s);
  38.     }
  39.  
  40. void opening_screen()
  41.     {
  42.     win *info;
  43.  
  44.     title.display(SoftFade);
  45.     delay(1000);
  46.     if (!(info = new win(75,65,175,75,NULL,4,5,11,9)))
  47.         {
  48.         settextmode();
  49.         reporterr(MemErr,"win init: opening_screen()");
  50.         return;
  51.         }
  52.     if (info->status != NoErr)
  53.         {
  54.         settextmode();
  55.         reporterr(info->status,"opening_screen()");
  56.         return;
  57.         }
  58.     small.setstyle(0,0,2,trans,5);
  59.     small.show(107,75,"Game Programmer's");
  60.     small.show(97,85,"Mode 13h Image Toolkit");
  61.     small.setstyle(4,0,2,trans,5);
  62.     small.show(132,101,"Version 1.0");
  63.     small.setstyle(0,0,1,trans,5);
  64.     small.show(90,117,"Gamer's Programming Workshop");
  65.     small.show(100,127,"GO GAMERS, section 11, CIS ");
  66.     delay(5000);
  67.     delete(info);
  68.     }
  69.  
  70. void announce(char *str)
  71.     {
  72.     win *info;
  73.  
  74.     if (!(info = new win(30,50,260,40,NULL,4,5,11,9)))
  75.         {
  76.         settextmode();
  77.         reporterr(MemErr,"win init: announce()");
  78.         return;
  79.         }
  80.     if (info->status != NoErr)
  81.         {
  82.         settextmode();
  83.         reporterr(info->status,"win init: announce()");
  84.         return;
  85.         }
  86.     small.setstyle(0,0,1,trans,3);
  87.     small.show(40,60,str);
  88.     small.setstyle(4,0,1,trans,3);
  89.     small.show(40,75,"Press any key...");
  90.     waitkey();
  91.     delete(info);
  92.     }
  93.  
  94. void about_kit()
  95.     {
  96.     win *info;
  97.  
  98.     if (!(info = new win(45,60,230,110,NULL,4,5,11,9)))
  99.         {
  100.         settextmode();
  101.         reporterr(MemErr,"win init: about_kit()");
  102.         return;
  103.         }
  104.     if (info->status != NoErr)
  105.         {
  106.         settextmode();
  107.         reporterr(info->status,"win init: about_kit()");
  108.         return;
  109.         }
  110.     small.setstyle(0,0,1,trans,3);
  111.     small.show(55,70,"The toolkit provides a set of functions for");
  112.     small.show(55,80,"basic mode 13h graphics operations, including");
  113.     small.show(55,90,"drawing primitives, windowing, text read and");
  114.     small.show(55,100,"write, and image handling. The window, font,");
  115.     small.show(55,110,"and image handling are provided through easy");
  116.     small.show(55,120,"to use class definitions. Image operations");
  117.     small.show(55,130,"include several different types of dissolves");
  118.     small.show(55,140,"wipes and fades, like the one you just saw.");
  119.     small.setstyle(4,0,1,trans,3);
  120.     small.show(55,155,"Press any key...");
  121.     waitkey();
  122.     delete(info);
  123.     announce("Let's take a look at some of the dissolve types...");
  124.     }
  125.  
  126. void demo_dissolves()
  127.     {
  128.     title.remove(SoftFade);
  129.     celtic.display(SoftFade);
  130.     delay(500);
  131.     announce("64 pass DAC palette fade (const SoftFade)");
  132.     celtic.remove(SoftFade);
  133.     rehack.display(SnapWipe);
  134.     delay(500);
  135.     announce("Simple block memory copy (const SnapWipe)");
  136.     rehack.remove(SnapWipe);
  137.     title.display(SplitVerticalWipe);
  138.     delay(500);
  139.     announce("Split vertical image wipe (const SplitVerticalWipe)");
  140.     title.remove(SplitVerticalWipe);
  141.     celtic.display(SplitHorizWipe);
  142.     delay(500);
  143.     announce("Split horizontal image wipe (const SplitHorizWipe)");
  144.     celtic.remove(SplitHorizWipe);
  145.     rehack.display(SlideVerticalWipe);
  146.     delay(500);
  147.     announce("Sliding vertical image wipe (const SlideVerticalWipe)");
  148.     rehack.remove(SoftFade);
  149.     title.display(SlideHorizWipe);
  150.     delay(500);
  151.     announce("Sliding horizontal image wipe (const SlideHorizWipe)");
  152.     title.remove(SoftFade);
  153.     celtic.display(VerticalDissolve);
  154.     delay(500);
  155.     announce("Vertical banded dissolve (const VerticalDissolve)");
  156.     celtic.remove(VerticalDissolve);
  157.     rehack.display(HorizDissolve);
  158.     delay(500);
  159.     announce("Horizontal banded dissolve (const HorizDissolve)");
  160.     rehack.remove(SoftFade);
  161.     clearscr(0);
  162.     }
  163.  
  164. void do_bm_window()
  165.     {
  166.     win *info;
  167.     void *map;
  168.     FILE *bmap;
  169.  
  170.     if ((map = new char[15744]) == NULL)
  171.         return;
  172.     if ((bmap = fopen("winmap.bit","rb")) == NULL)
  173.         {
  174.         settextmode();
  175.         reporterr(FileOpenErr,"do_bm_window()");
  176.         delete(map);
  177.         return;
  178.         }
  179.     if (fread(map,1,15744,bmap) != 15744)
  180.         {
  181.         settextmode();
  182.         reporterr(FileReadErr,"do_bm_window()");
  183.         delete(map);
  184.         fclose(bmap);
  185.         return;
  186.         }
  187.     fclose(bmap);
  188.     if (!(info = new win(62,71,192,82,(char *)map,0,5,0,0)))
  189.         {
  190.         settextmode();
  191.         reporterr(MemErr,"win init: do_bm_window()");
  192.         return;
  193.         }
  194.     if (info->status != NoErr)
  195.         {
  196.         settextmode();
  197.         reporterr(info->status,"win init: do_bm_window()");
  198.         return;
  199.         }
  200.     small.setstyle(0,0,1,trans,3);
  201.     small.show(85,91,"The windows can also have a");
  202.     small.show(85,101,"bitmap stored in system ram.");
  203.     small.show(85,111,"This background is stored on");
  204.     small.show(85,121,"disk as WINMAP.BIT.");
  205.     small.setstyle(4,0,1,trans,3);
  206.     small.show(85,136,"Press any key...");
  207.     waitkey();
  208.     delete(info);
  209.     delete(map);
  210.     rehack.remove(SplitVerticalWipe);
  211.     return;
  212.     }
  213.  
  214. void demo_window()
  215.     {
  216.     win *info;
  217.  
  218.     clearscr(155);
  219.     if (!(info = new win(45,60,230,95,NULL,4,5,11,9)))
  220.         {
  221.         settextmode();
  222.         reporterr(MemErr,"win init: demo_window()");
  223.         return;
  224.         }
  225.     if (info->status != NoErr)
  226.         {
  227.         settextmode();
  228.         reporterr(info->status,"win init: demo_window()");
  229.         return;
  230.         }
  231.     small.setstyle(0,0,1,trans,3);
  232.     small.show(55,70,"The win class is a base class for windowing");
  233.     small.show(55,80,"operations. It provides a foundation from");
  234.     small.show(55,90,"which new window classes can be descended. A");
  235.     small.show(55,100,"win class object saves it's background, and");
  236.     small.show(55,110,"has definable attributes for shadow, border,");
  237.     small.show(55,120,"background, size and position.");
  238.     small.setstyle(4,0,1,trans,3);
  239.     small.show(55,135,"Press any key...");
  240.     fadepalettein(0,256,default_pal);
  241.     waitkey();
  242.     delete(info);
  243.     if (!(info = new win(50,60,210,50,NULL,3,5,11,9)))
  244.         {
  245.         settextmode();
  246.         reporterr(MemErr,"win init: demo_window()");
  247.         return;
  248.         }
  249.     if (info->status != NoErr)
  250.         {
  251.         settextmode();
  252.         reporterr(info->status,"win init: demo_window()");
  253.         return;
  254.         }
  255.     small.setstyle(0,0,1,trans,3);
  256.     small.show(60,70,"200 x 75 window with 3 pixel blue border,");
  257.     small.show(60,80,"and 5 pixel shadow.");
  258.     small.setstyle(4,0,1,trans,3);
  259.     small.show(60,95,"Press any key...");
  260.     waitkey();
  261.     delete(info);
  262.     if (!(info = new win(50,60,210,50,NULL,0,0,11,0)))
  263.         {
  264.         settextmode();
  265.         reporterr(MemErr,"win init: demo_window()");
  266.         return;
  267.         }
  268.     if (info->status != NoErr)
  269.         {
  270.         settextmode();
  271.         reporterr(info->status,"win init: demo_window()");
  272.         return;
  273.         }
  274.     small.setstyle(0,0,1,trans,3);
  275.     small.show(60,70,"The same sized window with no border,");
  276.     small.show(60,80,"and no shadow.");
  277.     small.setstyle(4,0,1,trans,3);
  278.     small.show(60,95,"Press any key...");
  279.     waitkey();
  280.     delete(info);
  281.     rehack.display(VerticalDissolve);
  282.     delay(500);
  283.     do_bm_window();
  284.     }
  285.  
  286. void demo_font()
  287.     {
  288.     win *info;
  289.     char str[20];
  290.     char ascii_mask = (BCASE|NUMBER|PUNCT);
  291.  
  292.     celtic.display(SoftFade);
  293.     if (!(info = new win(30,50,260,80,NULL,0,5,255,0)))
  294.         {
  295.         settextmode();
  296.         reporterr(MemErr,"win init: demo_font()");
  297.         return;
  298.         }
  299.     if (info->status != NoErr)
  300.         {
  301.         settextmode();
  302.         reporterr(info->status,"win init: demo_font()");
  303.         return;
  304.         }
  305.     small.setstyle(0,0,1,trans,3);
  306.     small.show(40,60,"The font class provides a method for displaying");
  307.     small.show(40,70,"and reading strings of text. The setstyle()");
  308.     small.show(40,80,"method allows you to specify character spacing,");
  309.     small.show(40,90,"space character width, fore and background");
  310.     small.show(40,100,"color, and transparency.");
  311.     small.setstyle(32,0,1,trans,3);
  312.     small.show(40,115,"Press any key...");
  313.     waitkey();
  314.     delete(info);
  315.     if (!(info = new win(30,50,260,40,NULL,0,5,255,0)))
  316.         {
  317.         settextmode();
  318.         reporterr(MemErr,"win init: demo_font()");
  319.         return;
  320.         }
  321.     if (info->status != NoErr)
  322.         {
  323.         settextmode();
  324.         reporterr(info->status,"win init: demo_font()");
  325.         return;
  326.         }
  327.     small.setstyle(0,0,2,trans,3);
  328.     small.show(40,60,"Transparent text with 2 pixel spacing...");
  329.     small.setstyle(32,0,1,trans,3);
  330.     small.show(40,75,"Press any key...");
  331.     waitkey();
  332.     delete(info);
  333.  
  334.     if (!(info = new win(30,50,260,40,NULL,0,5,255,0)))
  335.         {
  336.         settextmode();
  337.         reporterr(MemErr,"win init: demo_font()");
  338.         return;
  339.         }
  340.     if (info->status != NoErr)
  341.         {
  342.         settextmode();
  343.         reporterr(info->status,"win init: demo_font()");
  344.         return;
  345.         }
  346.     small.setstyle(0,35,1,opaque,3);
  347.     small.show(40,60,"Opaque text with 1 pixel spacing...");
  348.     small.setstyle(32,0,1,trans,3);
  349.     small.show(40,75,"Press any key...");
  350.     waitkey();
  351.     delete(info);
  352.  
  353.     if (!(info = new win(30,50,260,75,NULL,0,5,255,0)))
  354.         {
  355.         settextmode();
  356.         reporterr(MemErr,"win init: demo_font()");
  357.         return;
  358.         }
  359.     if (info->status != NoErr)
  360.         {
  361.         settextmode();
  362.         reporterr(info->status,"win init: demo_font()");
  363.         return;
  364.         }
  365.     small.setstyle(0,255,1,trans,3);
  366.     small.show(40,60,"The class also provides a readstr() method");
  367.     small.show(40,70,"with a cursor and backspace enabled...");
  368.     small.readstr(40,85,str,20,ascii_mask);
  369.     small.show(40,100,str);
  370.     small.setstyle(32,0,1,trans,3);
  371.     small.show(40,115,"Press any key...");
  372.     waitkey();
  373.     delete(info);
  374.  
  375.     return;
  376.     }
  377.  
  378.  
  379. void demo_drawing()
  380.     {
  381.     int i;
  382.     win *info;
  383.  
  384.     if (!(info = new win(10,10,260,50,NULL,0,5,255,0)))
  385.         {
  386.         settextmode();
  387.         reporterr(MemErr,"win init: demo_font()");
  388.         return;
  389.         }
  390.     if (info->status != NoErr)
  391.         {
  392.         settextmode();
  393.         reporterr(info->status,"win init: demo_font()");
  394.         return;
  395.         }
  396.  
  397.     small.setstyle(0,0,1,trans,3);
  398.     small.show(20,20,"The images toolkit also provides some basic drawing");
  399.     small.show(20,30,"primitives...");
  400.     small.setstyle(4,0,1,trans,3);
  401.     small.show(20,45,"Press any key...");
  402.     waitkey();
  403.  
  404.     small.setstyle(0,0,1,trans,3);
  405.     clearscr(0);
  406.     loadpalette(0,256,default_pal);
  407.     clearscr(15);
  408.  
  409.     randomize();
  410.     for(i = 0; i < 100; i++)
  411.         {
  412.         line(160,50,random(320),random(100),random(256));
  413.         }
  414.     small.show(10,102,"like line drawing, and...");
  415.     randomize();
  416.     barfill(10,125,130,155,random(256));
  417.     barfill(30,130,200,160,random(256));
  418.     barfill(40,140,250,165,random(256));
  419.     barfill(50,150,300,150,random(256));
  420.  
  421.     small.show(10,170,"barfills, as well as pixel operations, getimage(),");
  422.     small.show(10,180,"putimage(), and copyimage().");
  423.     small.setstyle(4,0,1,trans,3);
  424.     small.show(10,190,"Press any key...");
  425.     waitkey();
  426.     clearscr(0);
  427.     return;
  428.     }
  429.  
  430. void closing_screen()
  431.     {
  432.     rehack.display(SoftFade);
  433.     small.setstyle(0,0,1,trans,3);
  434.     small.show(40,10,"The Mode 13h Images Toolkit is free for your use and");
  435.     small.show(40,20,"modification, subject to the guidelines layed out");
  436.     small.show(40,30,"in the accompanying source code and documentation.");
  437.     small.show(40,40,"We ask only that, if you change it, make it better,");
  438.     small.show(40,50,"and let us have a copy of your changes, so that we");
  439.     small.show(40,60,"can keep improving it.");
  440.     small.setstyle(14,0,1,trans,3);
  441.     small.show(40,130,"This toolkit is provided courtesy of the Gamer's");
  442.     small.show(40,140,"Programming Workshop, !GO GAMERS, section 11, CIS.");
  443.     small.setstyle(4,0,1,trans,3);
  444.     small.show(10,190,"Press any key...");
  445.     waitkey();
  446.     }
  447.  
  448. int main() {
  449.     char result;
  450.  
  451.     if (!small.installed()) {
  452.         printf("error installing font small\n");
  453.         return(1);
  454.     }
  455.     setgraphmode();
  456.     readpalette(0,256,default_pal);
  457.  
  458.     if (rehack.getstatus() != NoErr)
  459.         {
  460.         reporterr(rehack.getstatus(),"pcx constructor");
  461.         return(1);
  462.         }
  463.     if (celtic.getstatus() != NoErr)
  464.         {
  465.         reporterr(celtic.getstatus(),"pcx constructor");
  466.         return(1);
  467.         }
  468.     if (title.getstatus() != NoErr)
  469.         {
  470.         reporterr(title.getstatus(),"pcx constructor");
  471.         return(1);
  472.         }
  473.  
  474.     result = rehack.load(Bestfit);
  475.     if ((result != NoErr) && (result != MemErr))
  476.         reporterr(result,"function main()");
  477.     result = celtic.load(Bestfit);
  478.     if ((result != NoErr) && (result != MemErr))
  479.         reporterr(result,"function main()");
  480.     result = title.load(Bestfit);
  481.     if ((result != NoErr) && (result != MemErr))
  482.         reporterr(result,"function main()");
  483.  
  484.     opening_screen();
  485.     about_kit();
  486.     demo_dissolves();
  487.     demo_window();
  488.     demo_font();
  489.     demo_drawing();
  490.     closing_screen();
  491.     settextmode();
  492.     return(0);
  493. }
  494.  
  495.  
  496.  
  497.  
  498.